﻿using System.Collections.ObjectModel;

namespace XTrace.Viewer
{
	public class RealTimeXTraceListener : XTraceListener
	{
		readonly bool _showOnError;

		public RealTimeXTraceListener(bool showOnError)
		{
			_showOnError = showOnError;
		}

		public readonly ObservableCollection<XTraceEvent> Events = new ObservableCollection<XTraceEvent>();

		const int _max = 64;

		public override void Event(XTraceEvent traceEvent)
		{
			Events.Insert(0, traceEvent);
			if (Events.Count > _max)
			{
				var leave = _max * 3 / 4;
				for (int i = Events.Count - 1; i >= leave; i--)
				{
					Events.RemoveAt(i);
				}
			}

			if (traceEvent.Importance <= XEventImportance.Error)
			{
				//XTraceViewer.Instance.Bind(Events);
			}
		}
	}
}
